home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / Battleship 2.1 / Battleship.sounds.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-07  |  5.1 KB  |  193 lines  |  [TEXT/KAHL]

  1. #include    <Values.h>
  2. #include    <stdlib.h>
  3. #include    <Sound.h>
  4. #include    <Quickdraw.h>
  5.  
  6. #define kGridSize                    10
  7.  
  8. #define kBaseResID                    128
  9. #define kYouWindowID                kBaseResID
  10. #define kEnemyWindowID                kBaseResID + 1
  11. #define kTextWindowID                kBaseResID + 2
  12. #define kMoveToFront                (WindowPtr)-1L
  13.  
  14. #define kRandomUpperLimit            32768
  15. #define kRandomRange                kGridSize
  16.  
  17. #define kBombDropSnd                5000
  18. #define kExplosionSnd                5001
  19. #define kSplashSnd                    5002
  20. #define kYouSankSnd                    5003
  21. #define kYouWinSnd                    5004
  22. #define kYouLoseSnd                    5005
  23.  
  24. #define kNoSound                    0
  25. #define kSound                        1
  26.  
  27. #define wYou                        kBaseResID
  28. #define wComputer                    kBaseResID+1
  29. #define wText                        kBaseResID+2
  30.  
  31. #define kPixelSize                    20
  32. #define kNullDotID                    144
  33. #define kBWHitDotID                    143
  34. #define kHitDotID                    145
  35. #define kMissDotID                    146
  36. #define kMinSpacedShots                35
  37.  
  38. #define kHorizDestroyerID            200
  39. #define kVertDestroyerID            201
  40. #define kHorizCruiserID                202
  41. #define kVertCruiserID                203
  42. #define kHorizSubID                    204
  43. #define kVertSubID                    205
  44. #define kHorizBattleshipID            206
  45. #define kVertBattleshipID            207
  46. #define kHorizCarrierID                208
  47. #define kVertCarrierID                209
  48.  
  49. #define kCarrierMin                    2
  50. #define kCarrierMax                    2
  51. #define kBattleshipMin                1
  52. #define kBattleshipMax                2
  53. #define kCruiserMin                    1
  54. #define kCruiserMax                    1
  55. #define kSubMin                        1
  56. #define kSubMax                        1
  57. #define kDestroyerMin                0
  58. #define kDestroyerMax                1
  59.  
  60. #define kCarrierSize                5
  61. #define kBattleshipSize                4
  62. #define kCruiserSize                3
  63. #define kSubSize                    3
  64. #define kDestroyerSize                2
  65.  
  66. #define kNumShips                    5
  67. #define kNoShip                        -1
  68. #define kBattleship                    0
  69. #define kCarrier                    1
  70. #define kCruiser                    2
  71. #define kSub                        3
  72. #define kDestroyer                    4
  73.  
  74. #define mApple                        kBaseResID
  75. #define iAbout                        1
  76.  
  77. #define mFile                        kBaseResID + 1
  78. #define iNew                        1
  79. #define iQuit                        2
  80.  
  81. #define  mOptions                    kBaseResID + 3
  82. #define iSound                        1
  83.  
  84. #define kAddCheckMark                TRUE
  85. #define kRemoveCheckMark            FALSE
  86.  
  87. #define iPlayAgainCheckBox            1
  88. #define iQuitCheckBox                2
  89.  
  90. #define kExtraPopupPixels            25
  91.     
  92. #define kSpaceBarKey                49
  93.  
  94. #define    kVersionNumberStr            "\pv2.1"
  95.  
  96. #define kCongratulationsStr            "\pCongratulations!"
  97. #define kYouWinStr                    "\pYou Win!"
  98. #define kSorryStr                    "\pSorry."
  99. #define kYouLoseStr                    "\pYou Lose."
  100. #define kRotateStr                    "\pPress any key to rotate the ship."
  101. #define kPlaceStr                    "\pPress the mouse button to place the ship."
  102.  
  103. /***********/
  104. /* Structs */
  105. /***********/
  106.  
  107. typedef enum {
  108.     right, left, up, down
  109. } Direction;
  110.  
  111. typedef enum {
  112.     carrier = 1, battleship, cruiser, sub, destroyer
  113. } ShipsEnum;
  114.  
  115. typedef enum {
  116.     noTry = 144, hit, miss
  117. } cond;
  118.  
  119. typedef struct {
  120.     int        shipType;
  121.     int        shipResID;
  122.     cond    hitOrMiss;
  123. } Grid;
  124.  
  125.  
  126. /***********/
  127. /* Globals */
  128. /***********/
  129.  
  130. int            youCount = 0, enemyCount = 0, shotCount = 0;
  131. int            hitShips[kNumShips];
  132. Boolean        gDone, gYouHasGone = FALSE, gHasSound = FALSE, useColor;
  133. Grid        enemy [kGridSize] [kGridSize], you [kGridSize] [kGridSize];
  134. WindowPtr    enemyWindow, youWindow;
  135.  
  136.  
  137. /*************/
  138. /* Functions */
  139. /*************/
  140.  
  141. void    ToolBoxInit ( void );
  142. void    WindowInit ( void );
  143. void    MenuBarInit ( void );
  144. void    EventLoop ( void );
  145. void    DoEvent ( EventRecord *eventPtr );
  146. void    HandleMouseDown ( EventRecord *eventPtr );
  147. void    DoUpdate ( EventRecord *eventPtr );
  148. void    HandleMenuChoice ( long menuChoice );
  149. void    HandleAppleChoice ( short item );
  150. void    HandleFileChoice ( short item );
  151. void    NewGame ( void );
  152. void    DrawDots ( Grid theGrid[][kGridSize] );
  153. void    GridInit ( Grid aGrid[][kGridSize] );
  154. void    PlaceEnemyShips ( void );
  155. void    DrawShipPart ( int resID, Rect pictureRect );
  156. int        Randomize ( void );
  157. void    PlaceAnEnemyShip ( int shipSize, int min, int max, int c );
  158. Boolean    FitsHoriz ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  159. Boolean    FitsVert ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  160. void    CheckPoint ( Point mouseLocal );
  161. void    DrawOneDot ( int dotID, Rect *dotRect );
  162. void    PtToDotRect ( Point aPoint, Rect *aRect );
  163. void    PtToRect ( Point aPoint, Rect *aRect );
  164. void    EraseShipPart ( Rect pictureRect );
  165. void    PlaceAShip ( int theMin, int theMax, int theHorizID, int theShip );
  166. void    PtToShipRect ( Point aPoint, Rect *aRect, Boolean horiz, int min, int max );
  167. Boolean    Inbounds ( Point *tempPoint, Boolean horiz, int min, int max );
  168. void    DrawHorizDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  169. void    DrawVertDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  170. void    SetShipToGrid ( Grid theGrid[][kGridSize], Point tempPoint, 
  171.                             Boolean horiz, int min, int max, int c );
  172. Boolean    ItFits ( Boolean horiz, Point thePoint, int theMin, int theMax );
  173. cond    PlaceTheShot ( Point thePoint );
  174. void    PickEnemyShot ( void );
  175. void    HandleOptionsChoice ( short item );
  176. void    HandleSound ( void );
  177. Boolean    IsColour( void );
  178. Boolean    IsBadRandom ( Point thePoint, Boolean canCheck );
  179. void    InitShips ( void );
  180. int        CheckIfSink ( int theShip, Boolean play );
  181.  
  182.  
  183. /**********/
  184. /* Macros */
  185. /**********/
  186.  
  187. pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, short newItem)
  188.         = { 0x303C, 0x0304, 0xAA68 };
  189. pascal OSErr SetDialogCancelItem(DialogPtr theDialog, short newItem)
  190.         = { 0x303C, 0x0305, 0xAA68 };
  191.  
  192.  
  193.